package com.cn.xiaonuo.slbfinances.slborders.controller;

import cn.hutool.core.convert.Convert;
import com.cn.xiaonuo.common.entity.BusinessMessage;
import com.cn.xiaonuo.common.utils.LocalDateTimeUtils;
import com.cn.xiaonuo.common.utils.StringUtils;
import com.cn.xiaonuo.slbfinances.attractinfo.param.SlAttractUserParam;
import com.cn.xiaonuo.slbfinances.slborders.param.PaymentOrderParam;
import com.cn.xiaonuo.slbfinances.slborders.param.RefundReqParam;
import com.cn.xiaonuo.slbfinances.slborders.param.SlbOrderParam;
import com.cn.xiaonuo.slbfinances.slborders.param.CommonOrderParam;
import com.cn.xiaonuo.slbfinances.slborders.service.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@RestController
public class SlbOrdersController {

    @Resource
    private ISlbOrderService slbOrderService;
    @Resource
    private ICoverageRoyaltyService coverageRoyaltyService;
    @Resource
    private ICoverageShopWalletService coverageShopWalletService;
    @Resource
    private ICoverageOrderRefundService coverageOrderRefundService;
    @Resource
    private ICoverageRechargeService coverageRechargeService;


    @ApiOperation(value = "搜了宝订单管理--匀贸入账列表", notes = "搜了宝订单管理--匀贸入账列表")
    @PostMapping(value = "/api/slborder/yunList")
    public BusinessMessage yunList(@RequestBody SlbOrderParam param) {
        return this.slbOrderService.selectYunMao(param);
    }


    @ApiOperation(value = "搜了宝订单管理--商户结算", notes = "搜了宝订单管理--商户结算")
    @PostMapping(value = "/api/slborder/shopPaymentList")
    public BusinessMessage shopPaymentList(CommonOrderParam slbOrderReqParam) {
        return coverageRoyaltyService.shopPaymentList(slbOrderReqParam);
    }

    @ApiOperation(value = "搜了宝订单管理--商户结算记录", notes = "搜了宝订单管理--商户结算记录")
    @PostMapping(value = "/api/slborder/queryShopOrderList")
    public BusinessMessage queryShopOrderList(CommonOrderParam slbOrderReqParam) {
        return coverageShopWalletService.queryShopOrderList(slbOrderReqParam);
    }
    @ApiOperation(value = "搜了宝订单管理--退款记录", notes = "搜了宝订单管理--退款记录")
    @PostMapping(value = "/api/slborder/selectFinanceRefund")
    public BusinessMessage selectFinanceRefund(CommonOrderParam slbOrderReqParam) {
        BusinessMessage message = coverageOrderRefundService.selectFinanceRefund(slbOrderReqParam);
        return message;
    }
    @ApiOperation(value = "搜了宝订单管理--水电燃订单退款", notes = "搜了宝订单管理--水电燃订单退款")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "paramMap", value = "Map<rechargeOrderIds>")
    })
    @RequestMapping(value = "/api/slborder/dailyPayOrderRefund", method = RequestMethod.POST)
    public BusinessMessage dailyPayOrderRefund(@RequestBody Map<String,Object> paramMap) throws Exception{
        Object rechargeOrderIds = paramMap.get("rechargeOrderIds");
        List list = (List) rechargeOrderIds;
        return coverageRechargeService.dailyPayOrderRefund(list);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单ID",required = true,example = "10086"),
    })
    @ApiOperation(value = "搜了宝订单管理--查询订单详情", notes = "搜了宝订单管理--查询订单详情")
    @PostMapping(value ="/api/slborder/selectDetailInfo")
    public BusinessMessage selectDetailInfo(Integer orderId) {
        return this.slbOrderService.selectDetailInfo(orderId);
    }

    //04.卖家批量结款
    @ApiOperation(value = "搜了宝订单管理--卖家批量结款", notes = "搜了宝订单管理--卖家批量结款")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "paymentIdList", value = "支付订单ID列表", example = "[10086,10028]", required = true),
            @ApiImplicitParam(name = "userId", value = "用戶ID", example = "10086", required = true)
    })
    @RequestMapping(value ="/api/slborder/shopPayment", method = RequestMethod.POST)
    public BusinessMessage shopPayment(String paymentIdList, Integer userId) {
        return coverageRoyaltyService.shopPayment(paymentIdList, userId);
    }

    /**
     * 财务操作已经打款
     */
    @ApiOperation(value = "搜了宝订单管理--商户结算记录", notes = "搜了宝订单管理--商户结算记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "shopOrderIds", value = "商户订单ID数组", example = "[10086,10028]", required = true),
            @ApiImplicitParam(name = "userId", value = "用戶ID", example = "10086", required = true)
    })
    @RequestMapping(value ="/api/slborder/updateShopOrderStatus", method = RequestMethod.POST)
    public BusinessMessage updateShopOrderStatus(String shopOrderIds,Integer userId
    ) throws Exception{
        return coverageShopWalletService.updateShopOrderStatus(shopOrderIds,userId);
    }

    /**
     * 进出货订单
     */
    @ApiOperation(value = "搜了宝订单管理--进出货订单", notes = "搜了宝订单管理--进出货订单")
    @PostMapping(value ="/api/slborder/inOutOrder")
    public BusinessMessage inOutOrderList(SlbOrderParam slbOrderParam) {
        return slbOrderService.inOutOrderList(slbOrderParam);
    }
    /**
     * 进出货订单
     */
    @ApiOperation(value = "搜了宝订单管理--进出货订单导出", notes = "搜了宝订单管理--进出货订单导出")
    @GetMapping(value ="/api/slborder/inOutOrderExcel")
    public void inOutOrderExcel(HttpServletResponse response, SlbOrderParam slbOrderParam) throws Exception {
        slbOrderService.inOutOrderExcel(response,slbOrderParam);
    }

    @ApiOperation(value = "搜了宝订单管理--新版商户结算", notes = "搜了宝订单管理--新版商户结算")
    @PostMapping(value = "/api/slborder/shopPaymentPage")
    public BusinessMessage shopPaymentPage(PaymentOrderParam slbOrderReqParam) {
        return coverageRoyaltyService.shopPaymentPage(slbOrderReqParam);
    }
    @ApiOperation(value = "搜了宝订单管理--新版商户结算", notes = "搜了宝订单管理--新版商户结算")
    @GetMapping(value = "/api/slborder/shopPaymentExcel")
    public void shopPaymentExcel(HttpServletResponse response, PaymentOrderParam slbOrderReqParam) {
         coverageRoyaltyService.shopPaymentExcel(response,slbOrderReqParam);
    }

    @ApiOperation(value = "搜了宝订单管理--服务中心商户结算", notes = "搜了宝订单管理--服务中心商户结算")
    @PostMapping(value = "/api/slborder/fwzxShopPaymentPage")
    public BusinessMessage fwzxShopPaymentPage(PaymentOrderParam slbOrderReqParam) {
        return coverageRoyaltyService.fwzxShopPaymentPage(slbOrderReqParam);
    }
    @ApiOperation(value = "搜了宝订单管理--服务中心商户结算导出", notes = "搜了宝订单管理--服务中心商户结算导出")
    @GetMapping(value = "/api/slborder/fwzxShopPaymentExcel")
    public void fwzxShopPaymentExcel(HttpServletResponse response, PaymentOrderParam slbOrderReqParam) {
        coverageRoyaltyService.fwzxShopPaymentExcel(response,slbOrderReqParam);
    }

    @ApiOperation(value = "搜了宝订单管理--进出货结算", notes = "搜了宝订单管理--进出货结算")
    @PostMapping(value = "/api/slborder/inOutShopPaymentPage")
    public BusinessMessage inOutShopPaymentPage(PaymentOrderParam slbOrderReqParam) {
        return coverageRoyaltyService.inOutShopPaymentPage(slbOrderReqParam);
    }
    @ApiOperation(value = "搜了宝订单管理--进出货结算导出", notes = "搜了宝订单管理--进出货结算导出")
    @GetMapping(value = "/api/slborder/inOutShopPaymentExcel")
    public void inOutShopPaymentExcel(HttpServletResponse response, PaymentOrderParam slbOrderReqParam) {
        coverageRoyaltyService.inOutShopPaymentExcel(response,slbOrderReqParam);
    }

    @ApiOperation(value = "搜了宝订单管理--匀贸入账列表导出", notes = "搜了宝订单管理--匀贸入账列表导出")
    @GetMapping(value = "/api/slborder/yunListExcel")
    public void yunListExcel(HttpServletResponse response,SlbOrderParam param) {
          slbOrderService.selectYunMaoExcel(response,param);
    }

    @ApiOperation(value = "搜了宝订单管理--申请退款记录", notes = "搜了宝订单管理--申请退款记录")
    @PostMapping(value = "/api/slborder/applyFinanceRefund")
    public BusinessMessage applyFinanceRefund(CommonOrderParam slbOrderReqParam) {
        BusinessMessage message = coverageOrderRefundService.applyFinanceRefund(slbOrderReqParam);
        return message;
    }
  /*  @ApiOperation(value = "搜了宝订单管理--申请退款打款", notes = "搜了宝订单管理--申请退款打款")
    @PostMapping("/api/slborder/updateFinanceState")
    public BusinessMessage updateFinanceState(@RequestBody RefundReqParam param) {
        BusinessMessage message = coverageOrderRefundService.updateFinanceState(param);
        return message;
    }*/

    @ApiOperation(value = "搜了宝订单管理--申请退款打款", notes = "搜了宝订单管理--申请退款打款")
    @PostMapping("/api/slborder/updateFinanceState")
    public BusinessMessage updateFinanceState(Integer id, String userId,String  actmoney) {
        BusinessMessage message = coverageOrderRefundService.updateFinanceState(id, userId,actmoney);
        return message;
    }
}
